package com.alks.function.mapper.finance.salary;

import com.alks.entity.data.entity.PcBasicSalaryBsChg;
import com.alks.entity.data.entity.PcBasicSalaryWtChg;
import com.alks.entity.data.entity.PcCuttingSalary;
import com.alks.entity.data.entity.dispatch.MonthBonusEnd;
import com.alks.entity.data.entity.imes.CutProdDetailSalary;
import com.alks.function.data.dto.PcCuttingSalaryDto;
import com.alks.function.data.dto.administration.ChangeDto;
import com.alks.function.data.dto.administration.PcEmployeeWokeTypeDto;
import com.alks.function.data.dto.finance.salary.EmployeeListDto;
import com.alks.function.data.dto.finance.salary.PcBasicSalaryWtChgDto;
import com.alks.function.data.request.PcCuttingSalaryReq;
import com.alks.function.data.request.finance.salary.JobTypeRequest;
import com.alks.function.data.request.finance.salary.getEmployeeRequest;
import com.alks.function.data.request.finance.salary.getPcEmployeeWorkTypeRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface SalaryFileCreationMapper {

    /**
     * 工种工资建档-查询
     * @param workType
     */
    List<PcEmployeeWokeTypeDto> getPcEmployeeWokeTypeSalaryList(String workType);

    /**
     * 查询是否计时工种
     * @param workType
     * @return
     */
    Integer getEmployeeCalcType(String workType);
    Integer getEmployeeTempCalcType(String workType);

    /**
     * 工种工资修改
     * @param workType
     * @param salary
     * @param userName
     * @param now
     */
    void UpdatePcEmployeeWokeTypeSalary(String workType, String salary, String userName, LocalDateTime now);

    /**
     * 工种薪资变更记录
     * @param pcBasicSalaryWtChg
     */
    void addPcBasicSalaryWtChg(PcBasicSalaryWtChg pcBasicSalaryWtChg);

    /**
     * 工种薪资变更记录查询
     * @param request
     * @return
     */
    List<PcBasicSalaryWtChgDto> getPcBasicSalaryWtChgList(JobTypeRequest request);

    /**
     * 员工资料明细
     * @param request
     * @return
     */
    List<EmployeeListDto> getEmployeeList(getEmployeeRequest request);

    /**
     * 变更查询
     * @param request
     * @return
     */
    List<ChangeDto> getEmployeeChangeQuery(getEmployeeRequest request);

    /**
     * 根据工号查询信息
     * @param workerId
     * @return
     */
    EmployeeListDto getEmployeeList2(String workerId);


    /**
     * 批量修改工资
     * @param salary
     * @param now
     * @param workerIdList
     */
    void updatePcBasicSalary(@Param("salary") BigDecimal salary, @Param("now") LocalDateTime now, @Param("workerId") List<String> workerIdList);

    /**
     * 写入手动更改工资日志
     * @param list
     */
    void addPcBasicSalaryBsChgList(List<PcBasicSalaryBsChg> list);

    /**
     * 工种明细
     * @param request
     * @return
     */
    List<PcEmployeeWokeTypeDto> getJobTypeFilingQuery(getPcEmployeeWorkTypeRequest request);


    /**
     * 工种建档-修改
     * @param workTypeSeq
     * @param workTypeShort
     * @param calcType
     * @param userName
     * @param now
     */
    void updatePcEmployeeWorkTypeShort(Integer workTypeSeq, String workTypeShort, String calcType, String userName, LocalDateTime now);

    List<PcCuttingSalary> getPcCuttingSalary(PcCuttingSalaryReq req);

    BigDecimal getPcCuttingSalaryQtyTotal(PcCuttingSalaryReq req);

    BigDecimal getPcCuttingSalaryAmtTotal(PcCuttingSalaryReq req);

    List<String> getLotByPcLotHead(String lotNo);

    String getLot(String lotNo);


    void cancelSalary(@Param("list") List<PcCuttingSalary> list, @Param("name") String name);

    void setRemarkSalary(@Param("req") PcCuttingSalaryDto req, @Param("name") String name);

    @Select("select distinct type from PC_DISPATCH_CFM_DETAIL")
    List<String> getSalaryTypes();

    @Select("select distinct part_name from PC_DISPATCH_CFM_DETAIL")
    List<String> getPartNames();

    @Select("select distinct b.dept_name from  (select  distinct `name`  from  PC_DISPATCH_CFM_DETAIL ) a\n" +
            " left join PC_EMPLOYEE b\n" +
            " on a.`name` =  b.`name`\n" +
            " and b.status = 1\n" +
            "union \n" +
            "select distinct b.dept_name from (select  distinct `name`  from  PC_DISPATCH_CFM_DETAIL ) a\n" +
            " left join (select `name`,id_no,dept_name from PC_EMPLOYEE_DEL m  where not  exists (select 1 from PC_EMPLOYEE where id_no=m.id_no)) b\n" +
            " on a.`name` =  b.`name`")
    List<String> getDeptNames();

    @Select("  select distinct b.`name`,b.id_no idNo from  (select  distinct `name`  from  PC_DISPATCH_CFM_DETAIL ) a\n" +
            " left join PC_EMPLOYEE b\n" +
            " on a.`name` =  b.`name`\n" +
            " and b.status = 1\n" +
            " union\n" +
            " select distinct b.`name`,b.id_no idNo from (select  distinct `name`  from  PC_DISPATCH_CFM_DETAIL ) a\n" +
            " left join (select `name`,id_no,dept_name from PC_EMPLOYEE_DEL m  where not  exists (select 1 from PC_EMPLOYEE where id_no=m.id_no)) b\n" +
            " on a.`name` =  b.`name`")
    List<Map<String,String>> getWorkerNames();

    Integer getPcCuttingTotal(PcCuttingSalaryReq req);

    List<String> getLotNoByFinanceYymm(String financeYymm);


    List<Map<String, Object>> getPcCuttingCollect(List<String> list);

    String getFromBonus(String financeYymm);

    MonthBonusEnd selectByPrimaryKey(MonthBonusEnd monthBounusEnd);

    int countByCutJz(PcCuttingSalary cpds);

    int insertBatch(List<PcCuttingSalary> newList);

    List<PcCuttingSalary> getPcCuttingSalary1(PcCuttingSalaryDto req);

    List<CutProdDetailSalary> getPcCuttingCollectByLotNo(PcCuttingSalaryReq req);

    /*批量根据指令查询*/
    List<PcCuttingSalary> queryLotDetails(@Param("companyId") String companyId, @Param("list") List<String> list, @Param("type") String type);

    /**
     * 根据工种查询更新基本工资到工种薪资
     * @param workType
     */
    List<String> getUpdateByWorkType(@Param("workType") String workType);
}
